package usergroup

import (
	"context"

	uv1 "gitee.com/liangziyisheng/caas-platform-mc/api/user/v1"
	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/usergroup/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/consts"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) Info(ctx context.Context, req *v1.InfoReq) (res *v1.InfoRes, err error) {
	// return nil, gerror.NewCode(gcode.CodeNotImplemented)
	tenantCode := ctx.Value(consts.TokenClaims.TenantCode).(string)
	res = &v1.InfoRes{Id: req.Id, Users: []uv1.User{}}
	out, err := service.UserGroup().Info(ctx, &v1.InfoInput{Id: req.Id, TenantCode: tenantCode})
	if err != nil {
		return nil, err
	}
	for _, user := range out.Users {
		res.Users = append(res.Users, uv1.User{
			Id:         user.Id,
			Username:   user.Username,
			Type:       user.Type,
			Fullname:   user.Fullname,
			Email:      user.Email,
			Phone:      user.Phone,
			Status:     user.Status,
			EmployeeNo: user.EmployeeNo,
		})
	}
	return res, nil
}
